#ifndef NMC_GAME_HPP
#define NMC_GAME_HPP

#include "guichan/keylistener.hpp"

#include <string>

namespace gcn
{
	class Container;
	class Gui;
	class Font;
	class ImageFont;
	class ImageLoader;
}

namespace nmc
{
	class Configuration;
	class Console;
	class Graphics;
	class Logger;
	class Image;
	class Input;
	class Player;
	class Room;
	class Splash;
	class TileMap;
	class TileMapLoader;
	class ResourceHandler;
	
	class Game : public gcn::KeyListener
    {
    public:
		static const int LOGIC_FRAME_RATE = 10;
		static const int GRAPHICS_FRAME_RATE = 60;

		static Game* instance();

		void start();
		void shutdown();

        void run();

		Console* getConsole();
		gcn::Gui* getGui();
		long getTicks();
		void log(const std::string& message);

		Image* getImage(const std::string& filename);
		gcn::Font* getFont(const std::string& filename,
						   unsigned char glyphsFrom=32,
						   unsigned char glyphsTo=126);
		TileMap* getTileMap(const std::string& filename);
		Configuration* getConfiguration();
		
		bool isUpKeyHeldDown();
		bool isRightKeyHeldDown();
		bool isDownKeyHeldDown();
		bool isLeftKeyHeldDown();
		bool isActionKeyHeldDown();
		bool isJumpKeyHeldDown();

		void keyPressed(gcn::KeyEvent& keyEvent);
		void keyReleased(gcn::KeyEvent& keyEvent);

    private:
		Game();
		void logic();
		void draw();
	
		static Game* mInstance;
		
		Console* mConsole;
		Configuration* mConfiguration;
		Graphics* mGraphics;
		gcn::Gui* mGui;
		gcn::Container* mTop;
		Input* mInput;
		gcn::ImageLoader* mImageLoader;
		Logger* mLogger;
		ResourceHandler* mResourceHandler;
		Splash* mSplash;
		TileMapLoader* mTileMapLoader;
		

		bool mRunning;

		enum State
		{
			SPLASH,
			PLAYING,
			DEBUGGING,
			EDITING
		};

		State mState;

		Image* mDarkbitsLogo;
		gcn::Font* mFont;
		TileMap* mTileMap;
		Player* mPlayer;
		Room* mRoom;

		bool mUpKeyHeldDown;
		bool mRightKeyHeldDown;
		bool mDownKeyHeldDown;
		bool mLeftKeyHeldDown;
		bool mActionKeyHeldDown;
		bool mJumpKeyHeldDown;
    };
}
#endif